<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>case分支语句测试</title>
		<script type="text/javascript">
			var data = prompt("请输入数值1,运算符,数值2,中间请用逗号隔开：");
			var arr, splitChar;
			//if(data.contains(",")) {
				splitChar = ",";
			/* } else if (data.contains("，")) {
				splitChar = "，";
			} else {
				alter("输入错误，请按格式输入");
				// return;
			} */
			arr = data.split(splitChar);
			var num1 = parseInt(arr[0]);
			var middle = arr[1];
			var num2 = parseInt(arr[2]);
			switch (middle) {
				case "+":
					document.write("两个数的和：" + num1 + " + " + num2 + " = " + (num1 + num2));
					break;
				case "-":
					if (num1 < num2) {
						var temp = num1;
						num1 = num2;
						num2 = temp;
					}
					document.write("两个数的差：" + num1 + " - " + num2 + " = " + (num1 - num2));
					break;
				case "*":
					document.write("两个数的积：" + num1 + " * " + num2 + " = " + (num1 * num2));
					break;
				case "/":
					document.write("两个数的商：" + num1 + " / " + num2 + " = " + (num1 / num2));
					break;
				default:
					document.write("输入格式错误！");
			}
		</script>
	</head>
	<body>
	</body>
</html>
